/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package demo_login;

import db.JDBCUtil;
import gui.MainFrame;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author C079
 */
public class NewJFrame_delet extends javax.swing.JFrame {

    /**
     * Creates new form NewJFrame_delet
     */
    public NewJFrame_delet() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jTextField_deletId = new javax.swing.JTextField();
        jButton_deletSave = new javax.swing.JButton();
        jButton_deletCancle = new javax.swing.JButton();

        jLabel1.setText("请输入要删除的学号");

        jTextField_deletId.setText(" ");
        jTextField_deletId.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField_deletIdActionPerformed(evt);
            }
        });

        jButton_deletSave.setText("确定");
        jButton_deletSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_deletSaveActionPerformed(evt);
            }
        });

        jButton_deletCancle.setText("取消");
        jButton_deletCancle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_deletCancleActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(44, 44, 44)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jTextField_deletId)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(jButton_deletSave)
                        .addGap(59, 59, 59)
                        .addComponent(jButton_deletCancle)))
                .addContainerGap(44, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(jTextField_deletId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(36, 36, 36)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton_deletSave)
                    .addComponent(jButton_deletCancle))
                .addContainerGap(104, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTextField_deletIdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField_deletIdActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField_deletIdActionPerformed

    private void jButton_deletSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_deletSaveActionPerformed
        try {
            int n =0;
            // TODO add your handling code here:
            String id= jTextField_deletId.getText().trim();
            Connection conn=JDBCUtil.connectiontt();
            String sql="delete from scoreOfStu where stuno = ?";
            PreparedStatement pstat = conn.prepareStatement(sql);
            pstat.setString(1, id);
            n = pstat.executeUpdate();
            if(n==1){
                JOptionPane.showMessageDialog(null, "删除成功");
            }else{
                JOptionPane.showMessageDialog(null, "删除失败");
            }
        } catch (SQLException ex) {        
            Logger.getLogger(NewJFrame_delet.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }//GEN-LAST:event_jButton_deletSaveActionPerformed

    private void jButton_deletCancleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_deletCancleActionPerformed
        this.setVisible(false);
        new MainFrame().setVisible(true);
    }//GEN-LAST:event_jButton_deletCancleActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(NewJFrame_delet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(NewJFrame_delet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(NewJFrame_delet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(NewJFrame_delet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new NewJFrame_delet().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton_deletCancle;
    private javax.swing.JButton jButton_deletSave;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JTextField jTextField_deletId;
    // End of variables declaration//GEN-END:variables
}
